#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <set>

using namespace std;

multiset<int> l[1000005];
multiset<int> r[1000005];
int tree[4000005][3];

inline long long read()
{
    long long i = 0;
    long long xi = 1;
    char c;
    for (c = getchar(); (c != 45) && (c < 48 || c > 57); c = getchar());
    if (c == 45)
    {
        c = getchar();
        xi = -1;
    }
    for (; c >= 48 && c <= 57; c = getchar())
    {
        i = (i << 3) + (i << 1) + c - 48;
    }
    return xi * i;
}

void write(long long x)
{
    if (x < 0)
    {
        putchar('-');
        x = -x;
    }
    if (x > 9)
    {
        write(x / 10);
    }
    putchar(x % 10 + 48);
    return;
}

void modifyl(int k, int l, int r, int p, int x)
{
    if (l == r)
    {
        tree[k][0] = x;
        return;
    }
    int mid = (l + r) >> 1;
    if (p <= mid)
    {
        modifyl(k << 1, l, mid, p, x);
    }
    else
    {
        modifyl(k << 1 | 1, mid + 1, r, p, x);
    }
    tree[k][0] = max(tree[k << 1][0], tree[k << 1 | 1][0]);
    tree[k][1] = min(tree[k << 1][1], tree[k << 1 | 1][1]);
    tree[k][2] = min(tree[k << 1 | 1][1] - tree[k << 1][0] + 1, min(tree[k << 1][2], tree[k << 1 | 1][2]));
}

void modifyr(int k, int l, int r, int p, int x)
{
    if (l == r)
    {
        tree[k][1] = x;
        return;
    }
    int mid = (l + r) >> 1;
    if (p <= mid)
    {
        modifyr(k << 1, l, mid, p, x);
    }
    else
    {
        modifyr(k << 1 | 1, mid + 1, r, p, x);
    }
    tree[k][0] = max(tree[k << 1][0], tree[k << 1 | 1][0]);
    tree[k][1] = min(tree[k << 1][1], tree[k << 1 | 1][1]);
    tree[k][2] = min(tree[k << 1 | 1][1] - tree[k << 1][0] + 1, min(tree[k << 1][2], tree[k << 1 | 1][2]));
}

int main()
{
    freopen("stone.in", "r", stdin);
    freopen("stone.out", "w", stdout);
    int q = read();
    multiset<int> sl;
    multiset<int> sr;
    for (int i = 1; i <= 4000000; i++)
    {
        tree[i][0] = -0x3f3f3f3f;
        tree[i][1] = 0x3f3f3f3f;
        tree[i][2] = 0x3f3f3f3f;
    }
    for (int i = 1; i <= 1000000; i++)
    {
        l[i].insert(0x3f3f3f3f);
        r[i].insert(-0x3f3f3f3f);
    }
    for (int i = 1; i <= q; i++)
    {
        char c;
        scanf("%c", &c);
        if (c == 'A')
        {
            int ll = read();
            int rr = read() - 1;
            sl.insert(ll);
            sr.insert(rr);
            l[ll].insert(rr);
            r[rr].insert(ll);
            modifyl(1, 1, 1000000, rr, *--r[rr].end());
            modifyr(1, 1, 1000000, ll, *l[ll].begin());
            if (*sr.begin() >= *--sl.end())
            {
                write(*l[*--sl.end()].begin() - *--r[*sr.begin()].end() + 1);
                putchar('\n');
                continue;
            }
            write(tree[1][2]);
            putchar('\n');
            continue;
        }
        int ll = read();
        int rr = read() - 1;
        sl.erase(sl.find(ll));
        sr.erase(sr.find(rr));
        l[ll].erase(l[ll].find(rr));
        r[rr].erase(r[rr].find(ll));
        modifyl(1, 1, 1000000, rr, *--r[rr].end());
        modifyr(1, 1, 1000000, ll, *l[ll].begin());
        if (*sr.begin() >= *--sl.end())
        {
            write(*l[*--sl.end()].begin() - *--r[*sr.begin()].end() + 1);
            putchar('\n');
            continue;
        }
        write(tree[1][2]);
        putchar('\n');
    }
    return 0;
}